package com.neborosoft.FlyingDog.android.gui.adapters.listview;

import com.neborosoft.FlyingDog.logic.database.content.identified.Audio;
import com.neborosoft.lib.collections.IterableConcat;

import java.util.*;

/**
 * Created with IntelliJ IDEA.
 * User: CM
 * Date: 06.11.12
 * Time: 20:41
 * To change this template use File | Settings | File Templates.
 */
public class TrackList implements List<Audio> {
    private ArrayList<Audio> localTracks = new ArrayList<Audio>();
    private ArrayList<Audio> webTracks = new ArrayList<Audio>();

    @Override
    public void add(int location, Audio Audio) {
        throw new UnsupportedOperationException();         
    }

    @Override
    public boolean add(Audio Audio) {
        Audio audio = (Audio)Audio;
        if(audio.isLocal()){
            localTracks.add(audio);
        }
        else{
            webTracks.add(audio);
        }
        return true;
    }

    @Override
    public boolean addAll(int location, Collection collection) {
        throw new UnsupportedOperationException();
    }

    @Override
    public boolean addAll(Collection collection) {
        throw new UnsupportedOperationException();
    }

    @Override
    public void clear() {
        webTracks.clear();
        localTracks.clear();
    }

    @Override
    public boolean contains(Object object) {
        throw new UnsupportedOperationException();
    }

    @Override
    public boolean containsAll(Collection<?> collection) {
        throw new UnsupportedOperationException();
    }

    @Override
    public boolean removeAll(Collection<?> collection) {
        throw new UnsupportedOperationException();
    }

    @Override
    public boolean retainAll(Collection<?> collection) {
        throw new UnsupportedOperationException();
    }

    @Override
    public Audio get(int location) {
        int webIndex = location - localTracks.size() - 1;
        if(webIndex >= 0){
            return webTracks.get(webIndex);
        }
        else {
            return localTracks.get(location);
        }
    }

    @Override
    public int indexOf(Object object) {
        throw new UnsupportedOperationException();
    }

    @Override
    public boolean isEmpty() {
        return webTracks.isEmpty() && localTracks.isEmpty();
    }

    @Override
    public Iterator iterator() {
        return new IterableConcat(localTracks,webTracks).iterator();
    }

    @Override
    public int lastIndexOf(Object object) {
        throw new UnsupportedOperationException();
    }

    @Override
    public ListIterator listIterator() {
        throw new UnsupportedOperationException();
    }

    @Override
    public ListIterator listIterator(int location) {
        throw new UnsupportedOperationException();
    }

    @Override
    public Audio remove(int location) {
        throw new UnsupportedOperationException();
    }

    @Override
    public boolean remove(Object object) {
        throw new UnsupportedOperationException();
    }

    @Override
    public Audio set(int location, Audio Audio) {
        throw new UnsupportedOperationException();
    }

    @Override
    public int size() {
        return localTracks.size() + webTracks.size();
    }

    @Override
    public List subList(int start, int end) {
        throw new UnsupportedOperationException();
    }

    @Override
    public Audio[] toArray() {
        throw new UnsupportedOperationException();
    }

    @Override
    public <T> T[] toArray(T[] array) {
        throw new UnsupportedOperationException();
    }
}
